<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
     <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="/resource/js/jquery-3.6.0.js"></script>
<script type="text/javascript">
    function upload(){
    	var formData=new FormData($("form")[0]);
    	$.ajax({
    		url:"upload",
    		data:formData,
    		type:"post",
    		contentType:false,
    		processData:false,
    		success:function(obj){
    			$("img").prop("src",obj);
    			$("[name='pic']").val(obj);
    		}
    	})
    }

    function getCategory(cid){
    	$("[name='category.id']").html("<option value=''>==请选择==</option>");
    	$.post("getCategory",{"cid":cid},function(obj){
    	    for(var  i in obj){
    	    	$("[name='category.id']").append("<option value='"+obj[i].id+"'>"+obj[i].name+"</option>")
    	    }
    	},"json")
    	
    }
    

</script>

</head>
<body>
<form:form action="add" method="post" modelAttribute="a">
文章标题:<form:input path="title"/><br>
图片:<input type="file" name="file" onchange="upload()">
<img  src="" height="50px" width="50px">
<input type="text" name="pic">
<br><br>
所属频道:<form:select path="channel.id" onchange="getCategory(this.value)">
<form:option value="">==请选择==</form:option>
<c:forEach items="${ch}" var="c">
<option value="${c.id}" ${qv.channelId==c.id?'selected':'' }>${c.name}</option>
</c:forEach>
</form:select>
所属分类:<form:select path="category.id">
<form:option value="">==请选择==</form:option>
</form:select>
文章内容:<form:input path="context"/><br><br>
<form:button>提交</form:button>
</form:form>
</body>
</html>